package xyz.jpcr.covid19app.Activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import org.eazegraph.lib.charts.PieChart;
import org.eazegraph.lib.models.PieModel;

import java.text.NumberFormat;

import xyz.jpcr.covid19app.R;
import xyz.jpcr.covid19app.Util.IDateUtil;

import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_CONFIRMED;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_CURED;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_CURRENT_CONFIRMED;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_DEAD;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_LAST_UPDATE_TIME;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_NAME;
import static xyz.jpcr.covid19app.Adapter.CityAdapter.CITY_SUSPECTED;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_ACTIVE;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_CIRTICAL;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_CONFIRMED;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_DECEASED;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_NAME;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_RECOVERED;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_TESTS;
import static xyz.jpcr.covid19app.Adapter.CountryAdapter.COUNTRY_UPDATED;

public class PerCountryData extends AppCompatActivity {

    Toolbar toolbar;
    TextView country_CurrentConfirmed, country_confirmed, country_suspected, country_deaths, country_Cured, country_clock, country_day, country_tests;
    PieChart country_piechart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_per_country);

        toolbar = findViewById(R.id.layoutToolBar);

        country_CurrentConfirmed = findViewById(R.id.country_CurrentConfirmed);
        country_confirmed = findViewById(R.id.country_confirmed);
        country_suspected = findViewById(R.id.country_suspected);
        country_deaths = findViewById(R.id.country_deaths);
        country_Cured = findViewById(R.id.country_Cured);
        country_clock = findViewById(R.id.country_clock);
        country_day = findViewById(R.id.country_day);
        country_tests = findViewById(R.id.country_tests);
        country_piechart = findViewById(R.id.country_piechart);

        Intent intent = getIntent();
        String country_name = intent.getStringExtra(COUNTRY_NAME);
        long confirmed = intent.getLongExtra(COUNTRY_CONFIRMED, 0);
        int active = intent.getIntExtra(COUNTRY_ACTIVE, 0);
        int deceased = intent.getIntExtra(COUNTRY_DECEASED, 0);
        long tests = intent.getLongExtra(COUNTRY_TESTS, 0);
        int cirtical = intent.getIntExtra(COUNTRY_CIRTICAL, 0);
        int recovered = intent.getIntExtra(COUNTRY_RECOVERED, 0);
        long updated = intent.getLongExtra(COUNTRY_UPDATED, 0);

        toolbar.setTitle(country_name);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        country_CurrentConfirmed.setText(NumberFormat.getInstance().format(active));
        country_confirmed.setText(NumberFormat.getInstance().format(confirmed));
        country_suspected.setText(NumberFormat.getInstance().format(cirtical));
        country_deaths.setText(NumberFormat.getInstance().format(deceased));
        country_Cured.setText(NumberFormat.getInstance().format(recovered));
        country_tests.setText(NumberFormat.getInstance().format(tests));
        country_clock.setText(IDateUtil.getInstance().formatDate(updated, 2));
        country_day.setText(IDateUtil.getInstance().formatDate(updated, 1));

        country_piechart.addPieSlice(new PieModel("Current Confirmed", active, Color.parseColor("#fbc233")));
        country_piechart.addPieSlice(new PieModel("Suspected", cirtical, Color.parseColor("#08a045")));
        country_piechart.addPieSlice(new PieModel("Deaths", deceased, Color.parseColor("#f6404f")));
        country_piechart.addPieSlice(new PieModel("Cured", recovered, Color.parseColor("#FF03DAC5")));
        country_piechart.startAnimation();
    }
    
}